package com.hmall.order.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

@Component
@Slf4j
public class ItemHandlerlnterceptor implements HandlerInterceptor {

    @Autowired
    ThreadLocalConfig threadLocalConfig;

    @Override
    public boolean preHandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler) throws Exception {
        String header = request.getHeader("authorization");
        log.info("获取到的请求头为:"+header);
        if (StringUtils.isEmpty(handler)){
            threadLocalConfig.set((String) handler);
        }
        return true;
    }
}
